package com.coffeeloversupportlibrary.coffeelover.domain.article.adapter;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.coffeeloversupportlibrary.R;
import com.coffeeloversupportlibrary.coffeelover.contentshow.Details;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.coffeeloversupportlibrary.coffeelover.domain.article.type.PopularType;
import com.coffeeloversupportlibrary.databinding.PopularShowBinding;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/6 20:17
 * @projectName CoffeeLoverSupportLibrary
 * @className PopularAdapter.java
 * @description TODO
 *   mDiariesBinding = FragmentDiariesBinding.inflate(inflater, container, false);
 *    PopularShowBinding
 */
public class PopularAdapter implements Adapter<List<PopularType>>{
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.popular_show,parent,false);
        PopularShowBinding popularShowBinding=PopularShowBinding.bind(view);
        return new PopularArticleViewHolder(popularShowBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull List<PopularType> items, @NonNull RecyclerView.ViewHolder holder, int position) {
        PopularType item=items.get(position);
        List<Article> list=item.getItems();
        ((PopularArticleViewHolder)holder).popularShowBinding.popularContent.setText(list.get(0).getArticleTitle());
        //getSupportFragmentManager()
        Glide.with(((PopularArticleViewHolder)holder).itemView.getContext())
                .load(list.get(0).getArticleBanner())
                .into(((PopularArticleViewHolder)holder).popularShowBinding.popularImage);


        ((PopularArticleViewHolder)holder).popularShowBinding.popularImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(holder.itemView.getContext(), Details.class);
                intent.putExtra("articleId",list.get(0).getArticleId());
                intent.putExtra("title",list.get(0).getArticleTitle());
                ((PopularArticleViewHolder)holder).itemView.getContext().startActivity(intent);
            }
        });


    }
    static class PopularArticleViewHolder extends RecyclerView.ViewHolder{
        private PopularShowBinding popularShowBinding;
        public PopularArticleViewHolder(@NonNull PopularShowBinding popularShowBinding) {
            super(popularShowBinding.getRoot());
            this.popularShowBinding=popularShowBinding;
        }
    }

}
